<template>
  <div>
    <div style="height:80px">
      <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="map.findid" placeholder="指标编码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="map.findname" placeholder="指标名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">查询</el-button>
      </el-form-item>
    </el-form>
    </div>
    <div>
      <el-table
      :data="page.rows"
      border
      style="width: 100%">
      <el-table-column
        prop="besResultId"
        label="体检编号"
        width="200"
        align="center">
      </el-table-column>
      <el-table-column
        prop="besResultName"
        label="姓名"
        width="230"
        align="center">
      </el-table-column>
      <el-table-column
        prop="besResultGender"
        label="性别"
        width="190"
        align="center">
      </el-table-column>
      <el-table-column
        prop="besResultAge"
        label="年龄"
        width="190"
        align="center">
      </el-table-column>
      <el-table-column
        prop="disease.disName"
        label="体检结果"
        width="200"
        align="center">
      </el-table-column>
      <el-table-column
      label="操作"
      width="218"
      align="center"
      prop="besResultId">
      <template slot-scope="scope">
        <el-button type="text" @click="selschemeone(scope.row.besResultId)" v-if="scope.row.interId == null">制定方案</el-button>
        <el-button type="text" disabled v-if="scope.row.interId != null">已制定方案</el-button>
      </template>
    </el-table-column>
    </el-table>
    </div>
    <div class="block">
      <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[3, 5, 9, 15]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page.total">
        </el-pagination>
    </div>

    <el-dialog
      title="制定方案"
      :visible.sync="details"
      width="90%"
      :before-close="clearscheme"
      center>
      <el-row>
        <el-col :span="12">
          <el-card shadow="never" body-style="height: 400px">
            <div slot="header" class="clearfix">
              <span>患者信息</span>
            </div>
            <div>
              <el-tabs type="card" v-model="activeName">
                <el-tab-pane label="基本信息" name="first">
                  <el-descriptions class="margin-top" :column="2" border>
                      <el-descriptions-item>
                        <template slot="label">
                          档案号
                        </template>
                        {{result.besResultId}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          姓名
                        </template>
                        {{result.besResultName}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          性别
                        </template>
                        {{result.besResultGender}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          年龄
                        </template>
                        {{result.besResultAge}}
                      </el-descriptions-item>
                    </el-descriptions>
                    <el-descriptions class="margin-top" :column="1" border>
                      <el-descriptions-item labelStyle='width: 70px'>
                        <template slot="label">
                          疾病史
                        </template>
                        {{result.member.caseHistory.memCaseHisMedical}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          遗传史
                        </template>
                        {{result.member.caseHistory.memCaseHisClan}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          手术史
                        </template>
                        {{result.member.caseHistory.memCaseHisOperation}}
                      </el-descriptions-item>
                  </el-descriptions>
                </el-tab-pane>
                <el-tab-pane label="测评评估" name="second">
                  <el-row>
                    <el-col :span="6">档案号</el-col>
                    <el-col :span="6">测评日期</el-col>
                    <el-col :span="6">测评内容</el-col>
                    <el-col :span="6">测评结果</el-col>
                  </el-row>
                  <hr>
                  <el-row style="padding: 10px 0; margin-bottom: 15px ; background-color: #e5e9f2" >
                    <el-col :span="3">{{result.constitutionTest.conTestId}}</el-col>
                    <el-col :span="8">{{result.constitutionTest.conTestDatetime}}</el-col>
                    <el-col :span="6">体质测评</el-col>
                    <el-col :span="7">
                        <span v-if="result.constitutionTest.conTestPinghe == '是'"> 平和质 </span>
                        <span v-if="result.constitutionTest.conTestQixu == '是'"> 气虚质 </span>
                        <span v-if="result.constitutionTest.conTestYangxu == '是'"> 阳虚质 </span>
                        <span v-if="result.constitutionTest.conTestYinxu == '是'"> 阴虚质 </span>
                        <span v-if="result.constitutionTest.conTestTanshi == '是'"> 痰湿质 </span>
                        <span v-if="result.constitutionTest.conTestShire == '是'"> 湿热质 </span>
                        <span v-if="result.constitutionTest.conTestXueyu == '是'"> 血瘀质 </span>
                        <span v-if="result.constitutionTest.conTestQiyu == '是'"> 气郁质 </span>
                        <span v-if="result.constitutionTest.conTestTebing == '是'"> 特禀质 </span>
                    </el-col>
                  </el-row>
                  <el-row style="padding: 10px 0; margin-bottom: 30px ; background-color: #e5e9f2">
                    <el-col :span="3">{{result.mindTest.mindTestId}}</el-col>
                    <el-col :span="8">{{result.mindTest.mindTestDatetime}}</el-col>
                    <el-col :span="6">心理测评</el-col>
                    <el-col :span="7">
                        <span v-if="result.mindTest.mindTestQuti == '是'"> 躯体化 </span>
                        <span v-if="result.mindTest.mindTestQiangpozheng == '是'"> 强迫症 </span>
                        <span v-if="result.mindTest.mindTestRenji == '是'"> 人际关系敏感 </span>
                        <span v-if="result.mindTest.mindTestYouyu == '是'"> 犹豫 </span>
                        <span v-if="result.mindTest.mindTestJiaolv == '是'"> 焦虑 </span>
                        <span v-if="result.mindTest.mindTestDidui == '是'"> 敌对 </span>
                        <span v-if="result.mindTest.mindTestKongbu == '是'"> 恐怖 </span>
                        <span v-if="result.mindTest.mindTestPianzhi == '是'"> 偏执 </span>
                        <span v-if="result.mindTest.mindTestJingshenbing == '是'"> 精神病性 </span>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="3">档案号</el-col>
                    <el-col :span="8">测评日期</el-col>
                    <el-col :span="4">测评内容</el-col>
                    <el-col :span="3">膳食情况</el-col>
                    <el-col :span="3">运动情况</el-col>
                    <el-col :span="3">吸烟情况</el-col>
                  </el-row>
                  <hr>
                  <el-row style=" padding: 10px 0; margin-bottom: 15px ; background-color: #e5e9f2">
                    <el-col :span="3">{{result.riskTest.riskTestId}}</el-col>
                    <el-col :span="8">{{result.riskTest.riskTestDatetime}}</el-col>
                    <el-col :span="4">健康测评</el-col>
                    <el-col :span="3">{{result.riskTest.riskTestFood}}</el-col>
                    <el-col :span="3">{{result.riskTest.riskTestKeep}}</el-col>
                    <el-col :span="3">{{result.riskTest.riskTestSmoke}}</el-col>
                  </el-row>
                </el-tab-pane>
                <el-tab-pane label="体检信息" name="third">
                  <el-row style="margin-bottom: 15px">
                    <el-col :span="3">档案号</el-col>
                    <el-col :span="5">体检时间</el-col>
                    <el-col :span="8">体检套餐</el-col>
                    <el-col :span="8">体检结果</el-col>
                  </el-row>
                  <hr>
                  <el-row style=" padding: 10px 0; margin-bottom: 15px">
                    <el-col :span="3">{{result.besId}}</el-col>
                    <el-col :span="5">{{result.bespeak.besTime}}</el-col>
                    <el-col :span="8">{{result.setMeal.besSmName}}</el-col>
                    <el-col :span="8">{{result.besResultContent}}</el-col>
                  </el-row>
                </el-tab-pane>
              </el-tabs>
            </div>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card shadow="never" body-style="height: 400px">
            <div slot="header" class="clearfix">
              <span>方案信息</span>
            </div>
            <div>
              <el-tabs type="card" v-model="activetwoName">
                <el-tab-pane label="基本信息" name="first">
                  <el-descriptions class="margin-top" :column="2">
                      <el-descriptions-item label="档案号" >
                        {{result.besResultId}}
                      </el-descriptions-item>
                      <el-descriptions-item label="姓名">
                        {{result.besResultName}}
                      </el-descriptions-item>
                      <el-descriptions-item label="性别">
                        {{result.besResultGender}}
                      </el-descriptions-item>
                      <el-descriptions-item label="年龄">
                        {{result.besResultAge}}
                      </el-descriptions-item>
                    </el-descriptions>
                    <el-form :model="scheme" size="small" :rules="rules" ref="scheme" label-width="80px" class="demo-ruleForm">
                      <el-row>
                        <el-col :span="12">
                          <el-form-item label="方案名称" prop="interTitle">
                            <el-input v-model="scheme.interTitle"></el-input>
                          </el-form-item>
                          <el-form-item label="开始时间" prop="interStartTime">
                            <el-date-picker
                              v-model="scheme.interStartTime"
                              type="date"
                              :picker-options="pickerOptions"
                              value-format="yyyy-MM-dd"
                              placeholder="选择日期">
                            </el-date-picker>
                          </el-form-item>
                          <el-form-item label="干预周期" prop="interPeriod">
                            <el-input v-model="scheme.interPeriod"></el-input>
                          </el-form-item>
                          <el-form-item label="干预形式" prop="interShape">
                            <el-select v-model="scheme.interShape">
                              <el-option label="临床干预" value="临床干预" ></el-option>
                              <el-option label="药物干预" value="药物干预" ></el-option>
                              <el-option label="物理干预" value="物理干预" ></el-option>
                            </el-select>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="方案模板" >
                            <el-select v-model="scheme.temid" @change="subtemid()">
                              <el-option label="请选择" value="" selected></el-option>
                              <el-option v-for="tem in tems" :key="tem.interTempId" :label="tem.interTempTitle" :value="tem.interTempId"></el-option>
                            </el-select>
                          </el-form-item>
                          <el-form-item label="结束时间" prop="interEndTime">
                              <el-date-picker
                                v-model="scheme.interEndTime"
                                type="date"
                                :picker-options="downOptions"
                                value-format="yyyy-MM-dd"
                                placeholder="选择日期">
                              </el-date-picker>
                          </el-form-item>
                          <el-form-item label="定期回访" prop="interReturnVisit">
                            <el-input v-model="scheme.interReturnVisit"></el-input>
                          </el-form-item>
                          <el-form-item label="预期结果" prop="interTarget">
                            <el-input v-model="scheme.interTarget"></el-input>
                          </el-form-item>
                        </el-col>
                      </el-row>
                      <el-form-item label="干预内容" prop="interContent">
                        <el-input type="textarea" v-model="scheme.interContent"></el-input>
                      </el-form-item>
                    </el-form>
                </el-tab-pane>
                <el-tab-pane label="膳食方案" name="second" v-if="scheme.temid === ''">
                  <el-table
                    ref="food"
                    :data="foods"
                    highlight-current-row
                    @current-change="addfood"
                    style="width: 100%">
                    <el-table-column
                      type="index"
                      width="50">
                    </el-table-column>
                    <el-table-column
                      prop="foodZongTitle"
                      label="方案名称">
                    </el-table-column>
                    <el-table-column
                      prop="foodZongDesc"
                      label="方案价格">
                    </el-table-column>
                  </el-table>
                </el-tab-pane>
                <el-tab-pane label="运动方案" name="third" v-if="scheme.temid === ''">
                  <el-table
                    ref="keep"
                    :data="keeps"
                    highlight-current-row
                    @current-change="addkeep"
                    style="width: 100%">
                    <el-table-column
                      type="index"
                      width="50">
                    </el-table-column>
                    <el-table-column
                      prop="keepZongTitle"
                      label="方案名称">
                    </el-table-column>
                    <el-table-column
                      prop="keepZongDesc"
                      label="方案价格">
                    </el-table-column>
                  </el-table>
                </el-tab-pane>
                <el-tab-pane label="健康方案" name="fourth" v-if="scheme.temid === ''">
                  <el-table
                    ref="who"
                    :data="whos"
                    highlight-current-row
                    @current-change="addwho"
                    style="width: 100%">
                    <el-table-column
                      type="index"
                      width="50">
                    </el-table-column>
                    <el-table-column
                      prop="tempWhoTitle"
                      label="方案名称">
                    </el-table-column>
                    <el-table-column
                      prop="tempWhoDesc"
                      label="方案价格">
                    </el-table-column>
                  </el-table>
                </el-tab-pane>
              </el-tabs>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="clearscheme()">返 回</el-button>
        <el-button type="primary" @click="subscheme()">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import axios from 'axios'

export default ({
  name: 'scheme',
  data () {
    return {
      details: false,
      activeName: 'first',
      activetwoName: 'first',
      map: {
        index: '',
        findid: '',
        findname: ''
      },
      page: {},
      currentPage: 1,
      pageSize: 5,
      scheme: {
        interId: '',
        interTitle: '',
        tempWhoId: '',
        tempKeepId: '',
        tempFoodId: '',
        interStartTime: '',
        interEndTime: '',
        interTarget: '',
        interExecutePerson: '',
        interPeriod: '',
        interReturnVisit: '',
        interShape: '',
        interContent: '',
        hmId: '',
        interPlanCreateTime: '',
        interState: 0,
        temid: '',
        besResultId: ''
      },
      result: {
        besResultId: '',
        besId: '',
        besResultName: '',
        besResultGender: '',
        besResultAge: '',
        besResultUploadId: '',
        besResultNormal: '',
        besResultContent: '',
        besResultZip: '',
        besResultHealth: '',
        besResultDel: '',
        besResultState: '',
        perClassId: '',
        besResultConfirm: '',
        hmId: '',
        interId: '',
        member: {
          caseHistory: {
            memCaseHisMedical: '',
            memCaseHisClan: '',
            memCaseHisOperation: ''
          }
        },
        setMeal: {
          besSmName: ''
        },
        constitutionTest: {
          conTestId: '',
          conTestDatetime: '',
          conTestPinghe: '',
          conTestQixu: '',
          conTestYangxu: '',
          conTestYinxu: '',
          conTestTanshi: '',
          conTestShire: '',
          conTestXueyu: '',
          conTestTebing: ''
        },
        mindTest: {
          mindTestId: '',
          mindTestDatetime: '',
          mindTestQuti: '',
          mindTestQiangpozheng: '',
          mindTestRenji: '',
          mindTestYouyu: '',
          mindTestJiaolv: '',
          mindTestDidui: '',
          mindTestKongbu: '',
          mindTestPianzhi: '',
          mindTestJingshenbing: ''
        },
        riskTest: {
          riskTestId: '',
          riskTestDatetime: '',
          riskTestFood: '',
          riskTestKeep: '',
          riskTestSmoke: ''
        },
        bespeak: {
          besTime: ''
        }
      },
      foods: [],
      keeps: [],
      whos: [],
      tems: [],
      rules: {
        interTitle: [{ required: true, message: '请输入方案名称', trigger: 'blur' }],
        interStartTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
        interEndTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
        interTarget: [{ required: true, message: '请填写预期结果', trigger: 'blur' }],
        interPeriod: [{ required: true, message: '请填写干预周期', trigger: 'blur' }],
        interReturnVisit: [{ required: true, message: '请填写定期回访频率', trigger: 'blur' }],
        interShape: [{ required: true, message: '请选择干预方式', trigger: 'change' }],
        interContent: [{ required: true, message: '请填写干预内容', trigger: 'blur' }]
      },
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() < (Date.now() - 86400000)
        }
      },
      downOptions: {
        disabledDate (time) {
          return time.getTime() < (Date.now() - 86400000)
        }
      }
    }
  },
  methods: {
    // 改变页大小
    handleSizeChange (value) {
      this.pageSize = value
      this.selschemeall()
    },
    // 改变当前页码
    handleCurrentChange (value) {
      this.currentPage = value
      this.selschemeall()
    },
    selschemeall () {
      this.map.index = this.currentPage
      this.map.pageSize = this.pageSize
      axios.post('/api/scheme/selschemeall', this.map).then(result => {
        this.page = result.data
      })
    },
    selschemeone (id) {
      axios.get('/api/scheme/selschemeone/' + id).then(result => {
        this.result = result.data
      })
      this.selfoodall()
      this.selkeepall()
      this.selwhoall()
      this.seltemplateall()
      this.details = true
    },
    subscheme () {
      this.$refs.scheme.validate((valid) => {
        if (valid) {
          if ((this.scheme.tempFoodId !== '' && this.scheme.tempKeepId !== '' && this.scheme.tempWhoId !== '') || this.scheme.temid !== '') {
            this.scheme.interExecutePerson = this.result.besResultName
            let user = JSON.parse(sessionStorage.getItem('user'))
            this.scheme.hmId = user.hmId
            this.scheme.besResultId = this.result.besResultId
            axios.post('/api/scheme/subscheme', this.scheme).then(result => {
              if (result.data) {
                this.$message({
                  message: '制定方案成功',
                  type: 'success'
                })
              } else {
                this.$message.error('制定失败，请稍后重试')
              }
              this.clearscheme()
              this.selschemeall()
            })
          } else {
            if (this.scheme.tempFoodId === '' && this.scheme.tempKeepId === '' && this.scheme.tempWhoId === '') {
              this.$message.error('请分别选择膳食运动方案或者直接选择方案模板')
              this.activetwoName = 'second'
            } else {
              if (this.scheme.tempFoodId === '') {
                this.$message.error('请选择膳食方案或者直接选择方案模板')
                this.activetwoName = 'second'
              }
              if (this.scheme.tempKeepId === '') {
                this.$message.error('请选择运动方案或者直接选择方案模板')
                this.activetwoName = 'third'
              }
              if (this.scheme.tempWhoId === '') {
                this.$message.error('请选择健康方案或者直接选择方案模板')
                this.activetwoName = 'fourth'
              }
            }
          }
        }
      })
    },
    selfoodall () {
      axios.post('/api/scheme/selfoodall').then(result => {
        this.foods = result.data
      })
    },
    selkeepall () {
      axios.post('/api/scheme/selkeepall').then(result => {
        this.keeps = result.data
      })
    },
    selwhoall () {
      axios.post('/api/scheme/selwhoall').then(result => {
        this.whos = result.data
      })
    },
    seltemplateall () {
      axios.post('/api/scheme/seltemplateall').then(result => {
        this.tems = result.data
      })
    },
    addfood (val) {
      this.scheme.tempFoodId = val.foodZongId
    },
    addkeep (val) {
      this.scheme.tempKeepId = val.keepZongId
    },
    addwho (val) {
      this.scheme.tempWhoId = val.tempWhoId
    },
    subtemid () {
      if (this.scheme.temid !== '') {
        this.scheme.tempWhoId = ''
        this.scheme.tempKeepId = ''
        this.scheme.tempFoodId = ''
      }
    },
    clearscheme (scheme) {
      this.scheme = {
        interId: '',
        interTitle: '',
        tempWhoId: '',
        tempKeepId: '',
        tempFoodId: '',
        interStartTime: '',
        interEndTime: '',
        interTarget: '',
        interExecutePerson: '',
        interPeriod: '',
        interReturnVisit: '',
        interShape: '',
        interContent: '',
        hmId: '',
        interPlanCreateTime: '',
        interState: 0,
        temid: '',
        besResultId: ''
      }
      this.$refs.scheme.resetFields()
      this.activeName = 'first'
      this.activetwoName = 'first'
      this.details = false
    }
  },
  created () {
    this.selschemeall()
  }
})
</script>

<style scoped>

</style>
